home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
appshell
/
appprset.frm
< prev
next >
Wrap
Text File
|
1995-09-06
|
6KB
|
220 lines
VERSION 2.00
Begin Form AppPrSetup
BorderStyle = 3 'Fixed Double
Caption = "Printer Setup"
ClientHeight = 2010
ClientLeft = 360
ClientTop = 2310
ClientWidth = 5100
Height = 2415
Left = 300
LinkMode = 1 'Source
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2010
ScaleWidth = 5100
Top = 1965
Width = 5220
Begin CommandButton SetupCmd
Caption = "&Setup..."
Height = 315
Left = 3900
TabIndex = 3
Top = 1440
Width = 1035
End
Begin CommandButton CancelCmd
Cancel = -1 'True
Caption = "Cancel"
Height = 315
Left = 3900
TabIndex = 2
Top = 540
Width = 1035
End
Begin ListBox PrinterList
Height = 1395
Left = 120
Sorted = -1 'True
TabIndex = 4
Top = 420
Width = 3615
End
Begin CommandButton OKCmd
Caption = "OK"
Default = -1 'True
Height = 315
Left = 3900
TabIndex = 1
Top = 120
Width = 1035
End
Begin Label PrinterLabel
Caption = "&Printer:"
Height = 255
Left = 120
TabIndex = 0
Top = 120
Width = 735
End
End
Dim PrinterName(10) As String
Dim DriverName(10) As String
Dim PortName(10) As String
Sub CancelCmd_Click ()
Unload AppPrSetup
End Sub
Sub Form_Load ()
Dim SelPrName As String
Remove_Items_From_SysMenu AppPrSetup
Place_DialogBox_in_Form AppPrSetup, AppMain
If App_PrSetupTitle = "" Then
App_PrSetupTitle = "Printer Setup"
End If
AppPrSetup.Caption = App_PrSetupTitle
'
' empty the printer list box
'
Do While PrinterList.ListCount
PrinterList.RemoveItem 0
Loop
'
' if no currently selected printer, use the default
'
If App_PrinterName = "" Then
buf$ = String$(2048, 0)
BufSize% = Len(buf$)
y% = GetProfileString("windows", ByVal "device", "Error", buf$, BufSize%)
If buf$ <> "Error" Then
SelPrName = Left$(buf$, InStr(buf$, ",") - 1)
End If
Else
SelPrName = App_PrinterName
End If
'
' get the new list of printers
'
buf$ = String$(2048, 0)
y% = GetProfileString("devices", ByVal 0&, "Error", buf$, BufSize%)
'
' parse list and load list box
'
i% = -1 ' number of printers loaded
j% = 1
k% = InStr(j%, buf$, Chr$(0)) ' end index into buffer
While (k% <> 0 And j% < k%)
LoadPrinterList Mid$(buf$, j%, k% - j%), i%
j% = k% + 1
k% = InStr(j%, buf$, Chr$(0))
Wend
If i% < 0 Then
MsgBox "No Printers Found", MB_ICONSTOP, AppPrSetup.Caption
Else
'
' highlight currently selected printer in list box
'
For j% = 0 To i%
If Left$(PrinterList.List(j%), Len(SelPrName)) = SelPrName Then
PrinterList.ListIndex = j%
Exit For
End If
Next
End If
End Sub
Sub LoadPrinterList (PrName As String, PrNum As Integer)
buf$ = String$(80, 0)
BufSize% = Len(buf$)
key$ = PrName
'
' find out the driver name and port name
'
y% = GetProfileString("devices", ByVal key$, "Error", buf$, BufSize%)
buf$ = Left$(buf$, InStr(buf$, Chr$(0)) - 1)
i% = InStr(buf$, ",")
If i% > 0 Then
a$ = Left$(buf$, i% - 1)
b$ = Right$(buf$, Len(buf$) - i%)
If b$ <> "None" Then
PrinterList.AddItem key$ + " on " + b$
PrNum = PrNum + 1
PrinterName(PrNum) = PrName
DriverName(PrNum) = a$
PortName(PrNum) = b$
End If
End If
End Sub
Sub OKCmd_Click ()
x% = PrinterList.ListIndex
If x% < 0 Then
MsgBox "Must select a printer", MB_ICONINFORMATION, AppPrSetup.Caption
Else
For x% = 0 To 10
If Left$(PrinterList.Text, Len(PrinterName(x%))) = PrinterName(x%) Then Exit For
Next
App_PrinterName = PrinterName(x%)
App_PrinterDriver = DriverName(x%)
App_PrinterPort = PortName(x%)
Unload AppPrSetup
End If
End Sub
Sub PrinterList_DblClick ()
OKCmd_Click
End Sub
Sub SetupCmd_Click ()
x% = PrinterList.ListIndex
If x% < 0 Then
MsgBox "Must select a printer", MB_ICONINFORMATION, AppPrSetup.Caption
Else
'
' determine printer to setup
'
For x% = 0 To 10
If Left$(PrinterList.Text, Len(PrinterName(x%))) = PrinterName(x%) Then Exit For
Next
'
' call app shell dll routine to display printer setup dialog box
'
prn$ = PrinterName(x%)
dn$ = DriverName(x%) + ".drv"
pn$ = PortName(x%)
handle% = LoadLibrary("APPSHELL.DLL")
If handle% >= 32 Then
r% = AppShellPrSetup(AppPrSetup.hwnd, prn$, dn$, pn$)
If Not r% Then
MsgBox "Can't run printer setup;" + CRLF + "please check your installation", MB_ICONEXCLAMATION, APP_NAME
End If
FreeLibrary handle%
Else
MsgBox "Can't find printer setup program;" + CRLF + "reason code =" + Str$(handle%) + ";" + CRLF + "please check your software installation", MB_ICONEXCLAMATION, APP_NAME
End If
End If
End Sub